home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
umich
/
utils
/
nroff~06.zoo
/
text.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-07-18
|
18KB
|
1,077 lines
static char *rcsid_text_c="$Id: text.c,v 1.2 1992/07/16 10:38:32 rosenkra Exp $";
/*
* $Log: text.c,v $
* Revision 1.2 1992/07/16 10:38:32 rosenkra
* port to gcc, add tm,ie,el
*
*/
#undef OLD_WAY
/*
* text.c - text output processing portion of nroff word processor
*
* adapted for atariST/TOS by Bill Rosenkranz 11/89
* net: rosenkra@convex.com
* CIS: 71460,17
* GENIE: W.ROSENKRANZ
*
* original author:
*
* Stephen L. Browning
* 5723 North Parker Avenue
* Indianapolis, Indiana 46220
*
* history:
*
* - Originally written in BDS C;
* - Adapted for standard C by W. N. Paul
* - Heavily hacked up to conform to "real" nroff by Bill Rosenkranz
*/
#undef NRO_MAIN /* extern globals */
#include <stdio.h>
#include "nroff.h"
/*------------------------------*/
/* text */
/*------------------------------*/
void text (p)
REGISTER char *p;
{
/*
* main text processing
*/
REGISTER int i;
char wrdbuf[MAXLINE];
/*
* skip over leading blanks if in fill mode. we indent later.
* since leadbl does a robrk, do it if in .nf mode
*/
if (dc.fill == YES)
{
if (*p == ' ' || *p == '\n' || *p == '\r')
leadbl (p);
}
else
robrk ();
/*
* expand escape sequences
*/
expesc (p, wrdbuf);
/*
* test for how to output
*/
if (dc.ulval > 0)
{
/*
* underline (.ul)
*
* Because of the way underlining is handled,
* MAXLINE should be declared to be three times
* larger than the longest expected input line
* for underlining. Since many of the character
* buffers use this parameter, a lot of memory
* can be allocated when it may not really be
* needed. A MAXLINE of 180 would allow about
* 60 characters in the output line to be
* underlined (remember that only alphanumerics
* get underlined - no spaces or punctuation).
*/
underl (p, wrdbuf, MAXLINE);
--dc.ulval;
}
if (dc.cuval > 0)
{
/*
* continuous underline (.cu)
*/
underl (p, wrdbuf, MAXLINE);
--dc.cuval;
}
if (dc.boval > 0)
{
/*
* bold (.bo)
*/
bold (p, wrdbuf, MAXLINE);
--dc.boval;
}
if (dc.ceval > 0)
{
/*
* centered (.ce)
*/
center (p);
do_mc (p);
put (p);
--dc.ceval;
}
else if ((*p == '\r' || *p == '\n') && dc.fill == NO)
{
/*
* all blank line
*/
do_mc (p);
put (p);
}
else if (dc.fill == NO)
{
/*
* unfilled (.nf)
*/
do_mc (p);
put (p);
}
else
{
/*
* anything else...
*
* init escape char counter for this line...
*/
/* co.outesc = 0;*/
/*
* get a word and put it out. increment ptr to the next
* word.
*/
while ((i = getwrd (p, wrdbuf)) > 0)
{
/* co.outesc += countesc (wrdbuf);*/
putwrd (wrdbuf);
p += i;
}
}
}
/*------------------------------*/
/* bold */
/*------------------------------*/
void bold (p0, p1, size)
REGISTER char *p0;
REGISTER char *p1;
int size;
{
/*
* insert bold face text (by overstriking)
*/
REGISTER int i;
REGISTER int j;
j = 0;
for (i = 0; (p0[i] != '\n') && (j < size - 1); ++i)
{
if (isalpha (p0[i]) || isdigit (p0[i]))
{
p1[j++] = p0[i];
p1[j++] = '\b';
}
p1[j++] = p0[i];
}
p1[j++] = '\n';
p1[j] = EOS;
while (*p1 != EOS)
*p0++ = *p1++;
*p0 = EOS;
}
/*------------------------------*/
/* center */
/*------------------------------*/
void center (p)
REGISTER char *p;
{
/*
* center a line by setting tival
*/
dc.tival = max ((dc.rmval + dc.tival - width (p)) >> 1, 0);
}
/*------------------------------*/
/* expand */
/*------------------------------*/
void expand (p0, c, s)
REGISTER char *p0;
char c;
REGISTER char *s;
{
/*
* expand title buffer to include character string
*/
REGISTER char *p;
REGISTER char *q;
REGISTER char *r;
char tmp[MAXLINE];
p = p0;
q = tmp;
while (*p != EOS)
{
if (*p == c)
{
r = s;
while (*r != EOS)
*q++ = *r++;
}
else
*q++ = *p;
++p;
}
*q = EOS;
strcpy (p0, tmp); /* copy it back */
}
/*------------------------------*/
/* justcntr */
/*------------------------------*/
void justcntr (p, q, limit)
REGISTER char *p;
char *q;
int *limit;
{
/*
* center title text into print buffer
*/
REGISTER int len;
len = width (p);
q = &q[(limit[RIGHT] + limit[LEFT] - len) >> 1];
while (*p != EOS)
*q++ = *p++;
}
/*------------------------------*/
/* justleft */
/*------------------------------*/
void justleft (p, q, limit)
REGISTER char *p;
char *q;
int limit;
{
/*
* left justify title text into print buffer
*/
q = &q[limit];
while (*p != EOS)
*q++ = *p++;
}
/*------------------------------*/
/* justrite */
/*------------------------------*/
void justrite (p, q, limit)
REGISTER char *p;
char *q;
int limit;
{
/*
* right justify title text into print buffer
*/
REGISTER int len;
len = width (p);
q = &q[limit - len];
while (*p != EOS)
*q++ = *p++;
}
/*------------------------------*/
/* leadbl */
/*------------------------------*/
void leadbl (p)
REGISTER char *p;
{
/*
* delete leading blanks, set tival
*/
REGISTER int i;
REGISTER int j;
/*
* end current line and reset co struct
*/
robrk ();
/*
* skip spaces
*/
for (i = 0; p[i] == ' ' || p[i] == '\t'; ++i)
;
/*
* if not end of line, reset current temp indent
*/
if (p[i] != '\n' && p[i] != '\r')
dc.tival = i;
/*
* shift string
*/
for (j = 0; p[i] != EOS; ++j)
p[j] = p[i++];
p[j] = EOS;
}
/*------------------------------*/
/* pfoot */
/*------------------------------*/
void pfoot ()
{
/*
* put out page footer
*/
if (dc.prflg == TRUE)
{
skip (pg.m3val);
if (pg.m4val > 0)
{
if ((pg.curpag % 2) == 0)
{
puttl (pg.efoot, pg.eflim, pg.curpag);
}
else
{
puttl (pg.ofoot, pg.oflim, pg.curpag);
}
skip (pg.m4val - 1);
}
}
}
/*------------------------------*/
/* phead */
/*------------------------------*/
void phead ()
{
/*
* put out page header
*/
pg.curpag = pg.newpag;
if (pg.curpag >= pg.frstpg && pg.curpag <= pg.lastpg)
{
dc.prflg = TRUE;
}
else
{
dc.prflg = FALSE;
}
++pg.newpag;
set_ireg ("%", pg.newpag, 0);
if (dc.prflg == TRUE)
{
if (pg.m1val > 0)
{
skip (pg.m1val - 1);
if ((pg.curpag % 2) == 0)
{
puttl (pg.ehead, pg.ehlim, pg.curpag);
}
else
{
puttl (pg.ohead, pg.ohlim, pg.curpag);
}
}
skip (pg.m2val);
}
/*
* initialize lineno for the next page
*/
pg.lineno = pg.m1val + pg.m2val + 1;
set_ireg ("ln", pg.lineno, 0);
}
/*------------------------------*/
/* puttl */
/*------------------------------*/
void puttl (p, lim, pgno)
REGISTER char *p;
int *lim;
int pgno;
{
/*
* put out title or footer
*/
REGISTER int i;
char pn[8];
char t[MAXLINE];
char h[MAXLINE];
char delim;
itoda (pgno, pn, 6);
for (i = 0; i < MAXLINE; ++i)
h[i] = ' ';
delim = *p++;
p = getfield (p, t, delim);
expand (t, dc.pgchr, pn);
justleft (t, h, lim[LEFT]);
p = getfield (p, t, delim);
expand (t, dc.pgchr, pn);
justcntr (t, h, lim);
p = getfield (p, t, delim);
expand (t, dc.pgchr, pn);
justrite (t, h, lim[RIGHT]);
for (i = MAXLINE - 4; h[i] == ' '; --i)
h[i] = EOS;
#ifndef NO_CR
/* note: the order of the next 2 stmts has been reversed... */
h[++i] = '\r';
#endif
h[++i] = '\n';
h[++i] = EOS;
if (strlen (h) > 2)
{
for (i = 0; i < pg.offset; ++i)
prchar (' ', out_stream);
}
putlin (h, out_stream);
}
/*------------------------------*/
/* putwrd */
/*------------------------------*/
void putwrd (wrdbuf)
REGISTER char *wrdbuf;
{
/*
* put word in output buffer
*/
#ifdef DO_HYPH
ch